package com.cheng.web.action;


import javax.ws.rs.core.MediaType;

import org.apache.cxf.jaxrs.client.WebClient;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.cheng.bos.actionUtils.ActionUtils;
import com.cheng.domain.Customer;
import com.cheng.domain.base.Area;
import com.cheng.domain.constent.Constents;
import com.cheng.domain.takedelivery.Order;

@Namespace("/order")
@ParentPackage("json-default")
@Controller
@Scope("prototype")
public class OrderAction extends ActionUtils<Order> {
	
	private String sendAreaInfo;
	private String recAreaInfo;
	
	public void setSendAreaInfo(String sendAreaInfo) {
		this.sendAreaInfo = sendAreaInfo;
	}

	public void setRecAreaInfo(String recAreaInfo) {
		this.recAreaInfo = recAreaInfo;
	}

	@Action(value="order_save",results={@Result(name="success",location="../index.html",type="redirect")})
	public String saveOrder(){
		//设置收货地址和送货区域信息
		Area sendarea = new Area();
		Area recarea = new Area();
		if (sendAreaInfo != null || !sendAreaInfo.equals("")) {
			String[] strs = sendAreaInfo.split("/");
			sendarea.setProvince(strs[0]);
			sendarea.setCity(strs[1]);
			sendarea.setDistrict(strs[2]);
		}
		if (sendAreaInfo != null || !sendAreaInfo.equals("")) {
			String[] strs = recAreaInfo.split("/");
			recarea.setProvince(strs[0]);
			recarea.setCity(strs[1]);
			recarea.setDistrict(strs[2]);
		}
		model.setRecArea(recarea);
		model.setSendArea(sendarea);
		//关联当前登陆客户信息
		Customer customer = (Customer) ServletActionContext.getRequest().getSession().getAttribute("customer");
		model.setCustomer_id(customer.getId());

		WebClient.create(Constents.BOS_MANAGEMENT_URL+"/bos_management/service/orderService/saveorder").type(MediaType.APPLICATION_JSON).post(model);
		
		return SUCCESS;
	}
}
